package com.sghd.fight.module.game.service.skill.effect;

import com.sghd.fight.module.game.config.SkillConfig;
import com.sghd.fight.module.game.core.model.Unit;
import com.sghd.fight.module.game.service.room.IRoom;
import com.sghd.fight.module.game.service.skill.Context;
import com.sghd.pojo.fight.game.ChessType;
import com.sghd.pojo.fight.game.SkillReport;
import com.sghd.pojo.fight.game.TargetReport;
import org.apache.commons.collections.MapUtils;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author frank
 * @date 2018-12-18 14:33
 * @desc 暗夜旋律
 **/
@Component
public class DarknessMelodyEffect implements Effect {

    @Override
    public void execute(Context context, IRoom room, Unit owner, Unit target, Map<String, Object> ctx, SkillReport skillReport, TargetReport targetReport, SkillConfig config) {
        ChessType targetType = ChessType.valueOf(ctx.get(TARGET).toString());
        int targetCount = target.getMagic(targetType);
        owner.getMagic().update(targetType, targetCount);//吸山魔法值
        target.getMagic().update(targetType, -targetCount);//
        ChessType sourceType = ChessType.valueOf(ctx.get(SOURCE).toString());

        int level = owner.getSkillLevel(config.getId());
        Map<String, Object> attack2Level = MapUtils.getMap(ctx, String.valueOf(level));
        int limit = MapUtils.getIntValue(attack2Level, MSHIE_LIMIT);

        if(owner.getMagic(sourceType) > limit){ // 不消耗回合
            owner.setRound(owner.getRound() + config.getRound());
            skillReport.setRound(0);
        }
    }

    @Override
    public EffectType getType() {
        return EffectType.SK_DARKNESS_MELODY;
    }
}
